/****** Object:  Stored Procedure [dbo].spThanhToanInsert Script Date: 6/23/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[spThanhToanInsert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spThanhToanInsert]
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		25/06/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[spThanhToanInsert]
(
	@MaTT nvarchar(12) output,
	@NgayTT datetime,
	@PhuongThucTT nvarchar(50),
	@SoTien int,
	@GhiChu nvarchar(120),
	@MaCTPX nvarchar(12)
)
WITH ENCRYPTION

AS

SET NOCOUNT ON
if not exists (select * from [tbl_ThanhToan])
	Set @MaTT=1
else
	Set @MaTT=(select RIGHT(MAX([MaTT]),9) from [tbl_ThanhToan])
	Set @MaTT = REPLACE (@MaTT,'PAY','')+1
Set @MaTT='PAY'+@MaTT 

INSERT INTO [tbl_ThanhToan]
(
	[MaTT],
	[NgayTT],
	[PhuongThucTT],
	[SoTien],
	[GhiChu],
	[MaCTPX]
)
VALUES
(
	@MaTT,
	@NgayTT,
	@PhuongThucTT,
	@SoTien,
	@GhiChu,
	@MaCTPX
)
GO

--GRANT EXECUTE ON [dbo].[spThanhToanInsert] TO [sa]
--GO
